package com.uenpay.im.ui.old.activity.shake;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;

import org.json.JSONException;
import org.json.JSONObject;

public class GetShakePeopleInvokItem extends HttpInvokeItem {

	public class GetShakePeopleInvokItemResult {
		public int status;
		public String msg;
		public String nickname;
		public String distance;
		public int sex;
		public String custid;
	}

	public GetShakePeopleInvokItemResult getOutput() {
		return (GetShakePeopleInvokItemResult) GetResultObject();
	}

	public GetShakePeopleInvokItem(String longitude, String latitude) {
		String url = APIConfiguration.getBaseUrl() + "Shake/Shake/shake?longitude="
				+ longitude + "&latitude=" + latitude + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		GetShakePeopleInvokItemResult result = new GetShakePeopleInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject jsonObject = json.optJSONObject("data");
			if (jsonObject == null) {
				return result;
			}
			result.sex = jsonObject.optInt("sex");
			result.distance = jsonObject.optString("distance");
			result.nickname = jsonObject.optString("nickname");
			result.custid = jsonObject.optString("custid");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
